import numpy as np
import matplotlib.pyplot as plt

# # 对数变换绘图
# x = np.linspace(0, 255, 2048)
# y = np.log(x + 1)
# y_max = y.max()
# y = 255 / y_max * y
# plt.figure()
# plt.xlim(0, 255)
# plt.ylim(0, 255)
# x_ticks = np.arange(0, 256, 15)
# plt.xticks(x_ticks)
# y_ticks = np.arange(0, 256, 15)
# plt.yticks(y_ticks)
#
# plt.plot(x, y)
# plt.axvline(75, 0, 2, linestyle='dashed', color='red')
# plt.axhline(199, 0, 255, linestyle='dashed', color='red')
# plt.show()


# # 幂次变换用图 gamma > 1
# x = np.linspace(0, 255, 2048)
# y1 = np.power(x, 1)
# y2 = np.power(x, 1.5)
# y3 = np.power(x, 2)
# y4 = np.power(x, 2.5)
# y5 = np.power(x, 3)
# y6 = np.power(x, 4)
# y2 = 255 / y2.max() * y2
# y3 = 255 / y3.max() * y3
# y4 = 255 / y4.max() * y4
# y5 = 255 / y5.max() * y5
# y6 = 255 / y6.max() * y6
# plt.figure()
# plt.xlim(0, 255)
# plt.ylim(0, 255)
# x_ticks = np.arange(0, 256, 15)
# plt.xticks(x_ticks)
# y_ticks = np.arange(0, 256, 15)
# plt.yticks(y_ticks)
# plt.plot(x, y1, 'b-', label=r'$\gamma = 1$')
# plt.plot(x, y2, 'r-', label=r'$\gamma = 1.5$')
# plt.plot(x, y3, 'g-', label=r'$\gamma = 2$')
# plt.plot(x, y4, 'y-', label=r'$\gamma = 2.5$')
# plt.plot(x, y5, label=r'$\gamma = 3$')
# plt.plot(x, y6, label=r'$\gamma = 4$')
# plt.legend(loc=0)
#
# plt.show()


# # 幂次变换用图 gamma > 1
# x = np.linspace(0, 255, 2048)
# y1 = np.power(x, 1)
# y2 = np.power(x, 0.67)
# y3 = np.power(x, 0.5)
# y4 = np.power(x, 0.4)
# y5 = np.power(x, 0.2)
# y6 = np.power(x, 0.1)
# y2 = 255 / y2.max() * y2
# y3 = 255 / y3.max() * y3
# y4 = 255 / y4.max() * y4
# y5 = 255 / y5.max() * y5
# y6 = 255 / y6.max() * y6
# plt.figure()
# plt.xlim(0, 255)
# plt.ylim(0, 255)
# x_ticks = np.arange(0, 256, 15)
# plt.xticks(x_ticks)
# y_ticks = np.arange(0, 256, 15)
# plt.yticks(y_ticks)
# plt.plot(x, y1, 'b-', label=r'$\gamma = 1.0$')
# plt.plot(x, y2, 'r-', label=r'$\gamma = 0.67$')
# plt.plot(x, y3, 'g-', label=r'$\gamma = 0.5$')
# plt.plot(x, y4, 'y-', label=r'$\gamma = 0.4$')
# plt.plot(x, y5, label=r'$\gamma = 0.2$')
# plt.plot(x, y6, label=r'$\gamma = 0.1$')
# plt.legend(loc=4)
x = np.arange(0, 256, 1)
y = np.zeros(256)
y += 100
fig = plt.figure()
plt.subplot(211)
plt.xlim(0, 255)
plt.ylim(0, 150)
plt.bar(x, y, 0.5, color='b')

z = np.log(x + 1)
z = 255 / z.max() * z
z = z.astype(np.uint8)
for i in z:
    y[i] += 100

plt.subplot(212)
plt.xlim(0, 255)
plt.ylim(0, 800)
plt.bar(x, y, 0.5, color='r')
plt.show()